﻿using System;
using System.IO;
using System.Web;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using webapp4U.DAL;

using System.Web.UI;

namespace webapp4U.BOL
{
    public class Article : BizObject
    {
        #region "---Properties---"
        private int _articleID;
        private string _title;
        private string _excerpt;
        private string _imageURL;
        private int _imagewidth;
        private int _imageheight;
        private string _img1; // dung cho tour
        private string _img2; // dung cho tour
        private string _img3; // dung cho tour
        private string _authors;
        private string _body;
        private DateTime _postdate;
        private int _totalViews;
        private int _status;
        private int _priority;
        private int _articleCateID;
        private string _username;
        private string _languageCode;
               
        public int ArticleID
        {
            get { return _articleID; }
            set { _articleID = value; }
        }

        public string Title
        {
            get { return _title; }
            set { _title = value; }
        }

        public string Excerpt
        {
            get { return _excerpt; }
            set { _excerpt = value; }
        }

        public string ImageURL
        {
            get { return _imageURL; }
            set { _imageURL = value; }
        }
                  

        public int ImageWidth
        {
            get { return _imagewidth; }
            set { _imagewidth = value; }
        }

        public int ImageHeight
        {
            get { return _imageheight; }
            set { _imageheight = value; }
        }


        public string Img1
        {
            get { return  _img1; }
            set { _img1 = value; }
        }

        public string Img2
        {
            get { return _img2; }
            set { _img2 = value; }
        }

        public string Img3
        {
            get { return _img3; }
            set { _img3 = value; }
        }


        public string Authors
        {
            get { return _authors; }
            set { _authors = value; }
        }

   
        public string Body
        {
            get { return _body; }
            set { _body = value; }
        }

        public DateTime PostDate
        {
            get { return _postdate; }
            set { _postdate = value; }
        }

        public int TotalViews
        {
            get { return _totalViews; }
            set { _totalViews = value; }
        }

        public int Status
        {
            get { return _status; }
            set { _status = value; }
        }

        public int Priority
        {
            get { return _priority; }
            set { _priority = value; }
        }

        public int ArticleCateID
        {
            get { return _articleCateID; }
            set { _articleCateID = value; }
        }

        public string Username
        {
            get { return _username; }
            set { _username = value; }
        }

        public string LanguageCode
        {
            get { return _languageCode; }
            set { _languageCode = value; }
        }

        #endregion

        public Article()
        {
        
        }

        public static List<Article> GetArticleMenu(int ArticleCateID)
        {
            ArticleDAL db = new ArticleDAL();
            return db.GetArticleMenu(ArticleCateID);
        }


        public static List<Article> GetTuVan(int CateID)
        {
            ArticleDAL db = new ArticleDAL();
            return db.GetTuVan(CateID);
        }


        //Get GetArticleByParentID
        public static List<Article> GetArticleByParentID(int ParentID)
        {
            ArticleDAL db = new ArticleDAL();
            return db.GetArticleByParentID(ParentID);
        }
        
        public static List<Article> GetArticleRecent(Int32 ArticleCateID)
        {
            ArticleDAL db = new ArticleDAL();
            return db.GetArticleRecent(ArticleCateID);
        }


        public static List<Article> GetArticleHomePage(int ArticleCateID)
        {
            ArticleDAL db = new ArticleDAL();
            return db.GetArticleHomePage(ArticleCateID);
        }


        public static List<Article> GetArticleHomeByParentID(int ParentID)
        {
            ArticleDAL db = new ArticleDAL();
            return db.GetArticleHomeByParentArticleCateID(ParentID);
        }

        public static List<Article> Search(string Keyword, int CateID)
        {
            ArticleDAL db = new ArticleDAL();
            if (Keyword.ToString().Trim() != "")
                return db.Search(Keyword.Trim(), CateID);
            else
                return db.GetArticleByParentID(CateID);
        }


        //Get All Article
        public static List<Article> GetAllArticle(string LanguageCode)
        {
            ArticleDAL db = new ArticleDAL();
            return db.GetAllArticle(1, MAXROWS, LanguageCode);
        }

        //Get All Article
        public static List<Article> GetAllArticle(int PageIndex, int PageSize, string LanguageCode)
        {
            ArticleDAL db = new ArticleDAL();
            return db.GetAllArticle(PageIndex, PageSize, LanguageCode);
        }

        // Get Count All records of Table  Article
        public static int GetCountArticle(string LanguageCode)
        {
            ArticleDAL db = new ArticleDAL();
            return db.GetCountArticle(LanguageCode);
        }


        public static string GetImageURLByArticleID(int ArticleID)
        {
            ArticleDAL db = new ArticleDAL();
            return db.GetImageURLByArticleID(ArticleID);
        }

        public static int GetArticleCateIDByArticleID(int ArticleID)
        {
            ArticleDAL db = new ArticleDAL();
            return db.GetArticleCateIDByArticleID(ArticleID);
        }


        
        public static List<Article> GetTop2ArticleByArticleCateID(int ArticleCateID)
        {
            ArticleDAL db = new ArticleDAL();
            return db.GetTop2ArticleByArticleCateID(ArticleCateID);
        }


        public static List<Article> GetTop10ArticleByArticleCateID(int ArticleCateID)
        {
            ArticleDAL db = new ArticleDAL();
            return db.GetTop10ArticleByArticleCateID(ArticleCateID);
        }
        

        // lay thong tin theo loai tin
        public static List<Article> GetArticleByArticleCateID(int ArticleCateID)
        {
            ArticleDAL db = new ArticleDAL();
            return db.GetArticleByArticleCateID(ArticleCateID);
        }


        public static Article GetArticleByArticleID(int ArticleID)
        {
            ArticleDAL db = new ArticleDAL();
            return db.GetArticleByArticleID(ArticleID);
        }
                

        //Lay nhung tin tuc nhieu nguoi xem nhat de hien thi tren menu
        public static List<Article> GetArticleTopTotalviews(int ArticleCateID)
        {
            ArticleDAL db = new ArticleDAL();
            return db.GetArticleTopTotalviews(ArticleCateID);
        }

        //lay cac thong bao khac thong bao hien tai
        public static List<Article> GetArticleOtherArticleID(int ArticleID, int ArticleCateID)
        {
            ArticleDAL db = new ArticleDAL();
            return db.GetArticleOtherArticleID(ArticleID, ArticleCateID);
        }
        
        
        public static int Insert(Article obj)
        {
            ArticleDAL db = new ArticleDAL();
            return db.Insert(obj);
        }


        public static int Update(Article obj)
        {
            ArticleDAL db = new ArticleDAL();
            return db.Update(obj);
        }


        public static int UpdateTotalViews(int ArticleID)
        {
            ArticleDAL db = new ArticleDAL();
            return db.UpdateTotalViews(ArticleID);
        }


        public static int Delete(int ArticleID)
        {
            // xoa hinh truoc
            FileProcess.DeleteFile(Globals.PhysicalApplicationPath() + "UserUpload/Articles/" + GetImageURLByArticleID(ArticleID));
            ArticleDAL db = new ArticleDAL();
            return db.Delete(ArticleID);
        }

       
    }
}